<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Top Page</title>
</head>
<body>
    <p>当用户输入为个位数时，点击补零按钮补零为十位数，例如输入1，补零为01</p>
    <input type="text" name="num" id="num">
    <button onclick="zero()">补零</button>
</body>
<script>
    const zero = function () {
        var mun = document.getElementById("num");
        var num1 = mun.value;
        if (num1 == "" || num1 == null) {
            alert("输入错误，请重新输入！");
            location.reload();
        }else if (isNaN(num1)) {
            alert("输入的为非数字，请重新输入！");
            location.reload();
        }else {
            num1 = parseInt(num1);
            if (num1 < 10) {
                alert("返回数字前补充:0" + num1);
                console.log("返回数字前补充:0" + num1);
            }else {
                alert("返回数字" + num1);
                console.log("返回数字" + num1);
            }
        }
    }
</script>
</html>